from fastapi import APIRouter, Depends, HTTPException
from tortoise.contrib.pydantic import pydantic_queryset_creator

from dependencies import get_token_header
from models.application import ZhanApplication

router = APIRouter(
    prefix="/application",
    tags=["Application"],
    # dependencies=[Depends(get_token_header)],
    responses={404: {"description": "Not found"}},
)


@router.get("/")
async def read_items():
    ZhanApplicationDantic = pydantic_queryset_creator(ZhanApplication)
    p = await ZhanApplicationDantic.from_queryset(ZhanApplication.all())
    return p.json()


@router.put(
    "/{item_id}",
    tags=["custom"],
    responses={403: {"description": "Operation forbidden"}},
)
async def update_item(item_id: str):
    if item_id != "plumbus":
        raise HTTPException(
            status_code=403, detail="You can only update the item: plumbus"
        )
    return {"item_id": item_id, "name": "The great Plumbus"}